﻿Imports Mystery

Module Module1

    Private Sub setUpPro()
        Dim o As String 'just to have an object

        'o.getMystery().AssemblyRegister.Register(GetType(CatiaMystery.CatiaProduct).Assembly)
        o.getMystery().AssemblyRegister.Register(GetType(Module1).Assembly)


        Dim conf As MysteryConfiguration = o.getGlobalObject(Of MysteryConfiguration)()
        conf.db_connection_string = My.Settings.dbConnection

        Dim fileroot As String = My.Settings.FileRoot
        If String.IsNullOrEmpty(fileroot) Then
            fileroot = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MysteryData")
        End If

        conf.files_root_folder = New IO.DirectoryInfo(fileroot)
        If Not conf.files_root_folder.Exists Then
            conf.files_root_folder.Create()
        End If

        Dim cd As IContentDispatcher = o.getGlobalObject(Of IContentDispatcher)()
        Dim au As IAuthetication = o.getGlobalObject(Of IAuthetication)()
        Dim content_creator As IGlobalContentCreator = o.getGlobalObject(Of IGlobalContentCreator)()

        If Not cd.containsType(Of User)() Then

            Dim my_user As User = content_creator.getNewContent(Of User)()
            my_user.username = "uran"
            my_user.password = au.Hashstring("uranio")
            my_user.fullname = "Uranio238"
            cd.Add(my_user)
        End If

        Dim uranio As User = au.autheticate("uran", "uranio")
        If uranio IsNot Nothing Then
            Dim c As Client = cd.getAllByFilter(New Client With {.name = New ContentPropertyFilter(Of String)(uranio.username.value)}).FirstOrDefault
            If c Is Nothing Then
                c = content_creator.getNewContent(Of Client)()
                c.name = uranio.username
                cd.Add(c)
            End If
        End If

    End Sub

    Sub Main()
        setUpPro()


        Dim disp As New Dispatcher
        disp.start()

        Console.ReadLine()
    End Sub

End Module
